package core.proto;

import java.io.File;

import javax.swing.tree.DefaultMutableTreeNode;

import org.apache.commons.io.FilenameUtils;

public class CaseNode extends DefaultMutableTreeNode{
	private boolean visited= false;
	private String abspath="";
	// TODO use constant names instead.
	public static final int ISDIR = 0;
	public static final int ISCOLD = -1;
	public static final int ISHOT = 1;
	private int isCurrent = 0; //0 is directory, -1 if cold, 1 if hot
	String name; 
	boolean isRoot = false;
	
	/** Constructor: CaseNode(String path, boolean currentCase*/
	CaseNode(String name, String path, int isCurrent){
		super(name);
		this.name = FilenameUtils.getBaseName(new File(path).getName());
		visited= false;
		this.abspath=path;
		this.isCurrent= isCurrent;
	}

	public boolean isVisited(){
		return visited;
	}

	public String getAbsolutePath(){
		return this.abspath;
	}

	public int isCurrent(){
		return this.isCurrent;
	}

	public void setVisited(boolean a){
		this.visited= a;
	}

	public String getName(){
		return name;
	}
	
	public void markAsRoot(){
		isRoot = true;
	}
	
	// TODO very unclear about the intent of this method. 
	// why is it returning things conditionally? 
	//return only the name of the file/dir
	public String toString(){
		File f=new File(this.abspath);
		if (isRoot){
			return "Directory"; // quick hack to make root always appear with that name. 
		}
		if (f.getName().length() > 0){ 
			return FilenameUtils.getBaseName(f.getName()); 
		}else{
			return f.getPath();
		}
	}
}